Google IT support — Operating Systems (Linux)


1. Navigating the system

To navigate files and directories in operating systems you can use GUI or command-line interface (through shell). These files and directories are organized in a hierarchical directory tree (main directory branches off and holds other directories and files).

1.1. Basics

1.2. Terminal commands

System info:

Wildcards (symbols used to represent one or more characters):

Terminal shortcuts:

shortcutdescription
Ctrl + Shift + C / Vcopy/paste
Ctrl + A / Emove cursor to the begining/end of line
Ctrl + Wdelete a word to the left
Ctrl + U / Kdelete everything to the left/right of a cursor
Alt + B / Fmove one word back/forward
Tabtab completion
  
Ctrl + Shift + Topen new terminal tab
Ctrl + Shift + Wclose current terminal tab
Alt + <#>swith to <#>th terminal tab
Ctrl + Lclear terminal screen
Ctrl + Ckill current process
Ctrl + Zsuspend current process

To make command history be based on relevancy (instead of chronological order) add to ~/.inputrc the following:

1.3. File and text manipulation

1.4. I/O streams and the pipeline

<!-- graph LR id1(Standard Input) id2[Shell] id3(Standard Output) id4(Standard Error)

id1 -- #0 --> id2 id2 -- #1 --> id3 id2 -- #2 --> id4 -->


2. Users and permissions

2.1. Users and groups

2.2. Permissions

There are three different types of permissions: read, write and execute. To view files/directories permissions use ls -l:

Base-8Base-2Permissions
0000---
1001--x
2010-w-
3011-wx
4100r--
5101r-x
6110rw-
7111rwx

2.3. Special permissions

Sometimes you want to allow users do actions that require root privileges without giving them root access (e.g., to change user password you need to write into etc/shadow which is owned by root). For this reason special permissions exist:

  1. setuid

    • allows to run files by the permission of the owner
    • file with a setuid flag has an s instead of x in its list of owner permissions
  2. setgid

    • allows to run files as a member of the file group
    • file with a setgid flag has an s instead of x in its list of group permissions
  3. sticky bit

    • allows anyone to write to a file/directory, but only the owner or root can delete anything
    • file/directory with a sticky bit flag has a t instead of x in its list of permissions for other users
    • often used for temporary files

3. Package and software management

3.1. Software packages

Developers package software using software compiling tools. Different Linux distributions can use different methods for software packaging, e.g., Red Hat uses .rpm (Red Hat package manager) packages and Ubuntu uses .deb (Debian) packages. They contain instructions for a computer to perform, computer code and other files that program might use.

Packages usually rely on other pieces of code in order to work. In Linux these dependencies can be other packages or shared libraries. Standalone packages (e.g., .deb packages) don't install neccesary dependencies automatically, that's why package managers exist.

3.2. Package managers

A package manager makes sure that the process of software installation, removal, update, and dependency management is as easy and automatic as possible. APT (advanced package tool) is a default package manager for Ubuntu.

3.3. Archives

Archive is one or more files compressed into a single file.

3.4. Mobile app packages

Mobile applications usually can be downloaded only from a trusted source (like an app store). App store is a central managed marketplace for app developers to publish and sell mobile apps, i.e., the app store acts as package manager, and the app store service acts as a package repository.

3.5. Devices and drivers

Driver is a software that helps a hardware device interact with an OS.

In Linux, everything is a file, even hardware devices. So when a device is connected to a computer, a device file is created in the /dev directory.

3.6. OS updates

Installing latest system updates is a good practice to keep OS secure and get the newest features. In Ubuntu sudo apt upgrade will install the latest security updates, but won't upgrade the kernel and other core packages.


4. File systems

4.1. Review of file systems

A file system is used to keep track of files and file storage on a disk. The major operating systems have their own unique file systems:

4.2. Partitions

A storage device can be divided into partitions (pieces of the device that can be managed independently). Partitions essentially act as separate sub-devices, but they all use the same physical device.

Partition table is a component of a device that tells the OS how the device is partitioned (which are the boot partitions, space allocated for partitions, etc.)

There are two main partition table schemes which decide how to structure the information on partitions:

  1. MBR (master boot record)

    • mostly used in Windows, slowly being replaced by GPT
    • max volume size is 2 TB
    • max four primary partitions on a device (can add more with extended and logical partitions)
  2. GPT (GUID partition table)

    • max volume size is 8 ZB
    • max 128 partitions on a device (i.e., all partitions are primary)
    • UEFI booting is supported only for GPT devices

4.3. Disk partitioning, formatting and mounting

In Linux, disk partitioning and file system formatting can be done via GUI or with a few different partitioning terminal tools, e.g., with parted:

After a file system has been formatted it needs to be mounted to a directory (to make it accessible). Linux does this automatically, but it can also be done manually.

4.4. Virtual memory

Virtual memory allows OS provide the available physical memory (RAM) to the running applications. It creates a mapping between virtual and physical addresses. Virtual memory allows programs:

When a particular page of data (data block) isn't being used by an application, it gets evicted (copied out of memory onto the hard drive). This way memory resources are used most efficiently, and if a program needs a page that's not accessed a lot, the OS can still get to it in swap.

Manually create swap partition on a storage device:

4.5. Files and metadata

Linux uses a structure called inode to store and represent files and their metadata on a volume.

4.6. Disk usage

In Linux, disk usage and disk free utilities can be used to monitor disk usage. Linux does a better job than Windows in avoiding fragmentation of data on hard disk drives, so defragmentation is not needed.

4.7. File system repair

Data corruption could happen for lots of reasons:

Linux file system has features that minimize the danger of data corruption, as well as, features that recover data when it gets damaged:


5. Process management

5.1. Processes

Program is an application that a user can run.

Process is a program that's executing (i.e., user can have many processes of the same program running at the same time, e.g., browser tabs of a web browser).

5.2. Process monitoring

In Linux processes can be monitored:

  1. by viewing the files in /proc directory (since everything in Linux has a file, including processes)
  2. with ps utility

5.3. Process management

Sometimes user might want to interrupt a process before it fully completes. Signals are used for that purpose, they can be generated through other processes and software, or with keyboard shortcuts. Most common signals in Linux:

5.4. Jobs

In Linux, job is a task that has started running and not yet completed.

5.5. Resource monitoring

In Linux, user can monitor system resources use with several tools:


6. Operating systems in practice

6.1. Remote connection

SSH (secure shell) is a protocol used to securely connect to computers remotely.

6.2. Logs

In most systems, there is a service that runs in the background and constantly writes events to logs. In Linux, logs are stored in the /var/log directory.

6.3. OS deployment

Installing an OS on a large number of machines using traditional methods (e.g., with a USB stick) can be very time consuming, so other methods are used instead:

  1. Disk cloning

    1. Unmount device: umount /dev/sdx
    2. Create an image: sudo dd if=dev/sdx of=<path.img> bs=100M
  2. Network initiated deployment

    • request the images directly from the network
    • there are ways to use custom images too

6.4. Networking

6.5. Aliases

Users can create aliases for their most used commands. Aliases can be temporary (for a current terminal window) or permanent (modify ~/.bashrc).

6.6. Environment variables

In Linux, environment variables are a set of dynamic named values, that are used to store system settings (i.e., path to home directory, language settings, terminal settings, etc.). They are used by applications launched in shells or subshells.